/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-07
 * Time: 22:40
 */
class Counter {
    public  int count=0;
    synchronized public void counter() {
        count++;
    }
}
public class Test04 {

    public static void main(String[] args) {
        Counter con = new Counter();
        Thread t1 =new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                    con.counter();
                }
            }
        };

        Thread t2 =new Thread() {
            @Override
             public void run() {
                for (int i = 0; i < 50000; i++) {
                    con.counter();
                }
            }
        };

        t1.start();;
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(con.count);
    }
}
